package com.cherrish.demo;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;

/**
 * @author cherrishccl
 * @time 2019-03-29 8:56
 * @name Lottery
 * @desc: 彩票
 */
public class Lottery {

    public static void main(String[] args) {
      doubleChromosphere();
      superLotto();
    }

    /**
     * 双色球
     */
    private static void doubleChromosphere(){
        randomBall(33, 6, 16, 1);
    }

    /**
     * 大乐透
     */
    private static void superLotto(){
        randomBall(35, 5, 12, 2);
    }

    private static void randomBall(int red, int redSize,int blue, int blueSize){
        TreeMap<Integer, String> map = new TreeMap<>();
        random(red, map, redSize);
        System.out.print("红球: ");
        printMap(map);
        if(blueSize > 0){
            map = new TreeMap<>();
            random(blue, map, blueSize);
            System.out.print("蓝球: ");
            printMap(map);
        }
    }

    private static void random(int range, TreeMap<Integer, String> map, int size){
        if(size == map.size()){
            return;
        }
        int index = new Random().nextInt(range) + 1;
        String val =  "" + index;
        if(index < 10){
            val = "0" + val;
        }
        map.put(index, val);
        random(range, map, size);
    }

    private static void printMap(Map<Integer, String> map){
        for(Map.Entry<Integer, String> entry : map.entrySet()){
            System.out.print(entry.getValue() + "  ");
        }
        System.out.println();
    }
}
